package com.edie.customview.data.net;

import com.edie.customview.data.net.api.UserApi;
import com.edie.customview.data.net.entity.HttpResponse;
import com.edie.customview.data.net.entity.UserInfoEntity;

import io.reactivex.Observable;

/**
 * edie create on 2018/7/11
 */
public class RemoteClient {

    private UserApi mUserApi;

    private RemoteClient() {
        mUserApi = NetClient.getInstance().createUserApi();
    }

    /**
     * 获取单例
     */
    public static RemoteClient getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public Observable<UserInfoEntity> postLogin(String hashid, String uid) {
        return request(mUserApi.loadUserInfoNew(hashid, uid));
//        return mUserApi
//                .loadUserInfoNew(hashid, uid)
//                .compose(new HttpObservableTransformer<>());
    }

    public <T> Observable<T> request(Observable<HttpResponse<T>> response) {
        return response.compose(new HttpObservableTransformer<>());
    }

    /**
     * 在访问HttpUtil时创建单例
     */
    private static class SingletonHolder {
        private static final RemoteClient INSTANCE = new RemoteClient();
    }
}
